﻿package mortal.game.view.tianDiRank
{
    import __AS3__.vec.*;
    import com.gengine.core.frame.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.events.*;
    import com.mui.utils.*;
    import extend.language.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.tianDiRank.data.*;
    import mortal.game.view.tianDiRank.panel.*;
    import mortal.game.view.wizard.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class TianDiRankModule extends BaseWindow
    {
        private var _tab:GTabarNew;
        private var _tabData:Array;
        public var curPanel:GSprite;
        private var _selectIndex:int = -1;
        private var _clsVec:Vector.<Class>;
        private var _timer:SecTimer;

        public function TianDiRankModule(param1:ILayer = null)
        {
            this._clsVec = new Vector.<Class>;
            super(param1);
            setSize(900, 590);
            title = "王权争霸";
            this.layer = LayerManager.windowLayer3D;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            LoaderHelp.addResCallBack(ResFileConst.tianDiRank, this.onResLoad);
            return;
        }// end function

        private function onResLoad() : void
        {
            this.initPanel();
            this._tab = UIFactory.gTabBarNew(7, 36, this._tabData, 891, 530, 65, 26, this, this.onTabChangeHd);
            this._timer = new SecTimer(60);
            this._timer.addListener(TimerType.ENTERFRAME, this.onFreshHd);
            this._timer.start();
            this.openByTab();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._tab = null;
            if (this.curPanel)
            {
                this.curPanel.dispose();
                this.curPanel = null;
            }
            this._clsVec.length = 0;
            var _loc_2:int = 0;
            this._tabData.length = 0;
            this._selectIndex = -1;
            this._timer = null;
            LoaderHelp.removeResEvent(ResFileConst.tianDiRank, this.onResLoad);
            return;
        }// end function

        private function openByTab() : void
        {
            var _loc_1:* = Cache.instance.tianDi.openIndex;
            if (_loc_1 && _loc_1.length > 0)
            {
                if ((this._tabData.length - 1) >= _loc_1[0])
                {
                    this._tab.selectedIndex = _loc_1[0];
                }
                else
                {
                    this._tab.selectedIndex = 0;
                }
                if (_loc_1.length == 1)
                {
                    Cache.instance.tianDi.openIndex = null;
                }
            }
            else
            {
                this._tab.selectedIndex = this._tab.dataProvider.length - 1;
            }
            this.onTabChangeHd(null);
            return;
        }// end function

        private function initPanel() : void
        {
            this._tabData = [];
            this.addDiPanel();
            this.addTianPanel();
            return;
        }// end function

        private function addDiPanel() : void
        {
            this._tabData.push({label:Language.getString(71982), name:"diRank"});
            this._clsVec.push(TianDiRankDiShowPanel);
            return;
        }// end function

        private function addTianPanel() : void
        {
            if (TianDiRankUtil.isOverServerOpen())
            {
                this._tabData.push({label:"" + Language.getString(71983), name:"tianRank"});
                this._clsVec.push(TianDiRankDiShowPanel);
            }
            return;
        }// end function

        private function onTabChangeHd(event:MuiEvent) : void
        {
            var _loc_2:* = this._tab.selectedIndex;
            if (_loc_2 < 0 || this._clsVec == null || _loc_2 >= this._clsVec.length)
            {
                return;
            }
            if (this._selectIndex == _loc_2)
            {
                return;
            }
            this._selectIndex = _loc_2;
            if (this._selectIndex == 0)
            {
                Cache.instance.tianDi.isDiRankFlag = true;
            }
            else
            {
                Cache.instance.tianDi.isDiRankFlag = false;
            }
            if (this.curPanel && !this.curPanel.isDisposed)
            {
                this.curPanel.dispose();
            }
            var _loc_3:* = UICompomentPool.getUICompoment(this._clsVec[_loc_2], this) as TianDiRankDiShowPanel;
            if (this._selectIndex == 0)
            {
                _loc_3.isDiRankFlag = true;
            }
            else
            {
                _loc_3.isDiRankFlag = false;
            }
            this.addChild(_loc_3);
            this.curPanel = _loc_3;
            if (TianDiEnterPanel.hasInstance() && TianDiEnterPanel.instance.isHide == false)
            {
                TianDiEnterPanel.instance.hide();
            }
            return;
        }// end function

        private function onFreshHd(param1:SecTimer) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.TianDiRankGetListInfo));
            return;
        }// end function

    }
}
